<?php
	 
	function get_data_list($karyawan_id , $pr_yearly_income_id){

		$pr_yearly_incomes=my_get_data_by_id('pr_yearly_income','pr_yearly_income_id',$pr_yearly_income_id) ;
		
		$query = "
				SELECT * FROM pr_yearly_income_karyawan a
				WHERE a.pr_yearly_income_id={$pr_yearly_income_id} 
				AND a.karyawan_id={$karyawan_id} 
				ORDER BY a.komponen_id
			";	
	
		$rs = my_query($query);
		$datas = array();
		while($row = my_fetch_array($rs)){
			$datas[$row['komponen_id']] = $row['nominal'];
		}
		return $datas;
	}

	$known_mime_types=array(
		"pdf" => "application/pdf",
		"txt" => "text/plain",
		"html" => "text/html",
		"htm" => "text/html",
		"exe" => "application/octet-stream",
		"zip" => "application/zip",
		"doc" => "application/msword",
		"xls" => "application/vnd.ms-excel",
		"ppt" => "application/vnd.ms-powerpoint",
		"gif" => "image/gif",
		"png" => "image/png",
		"jpeg"=> "image/jpg",
		"jpg" =>  "image/jpg",
		"php" => "text/plain"
	 );
	 
	 if($mime_type==''){
		 $file_extension = strtolower(substr(strrchr($file,"."),1));
		 if(array_key_exists($file_extension, $known_mime_types)){
			$mime_type=$known_mime_types[$file_extension];
		 } else {
			$mime_type="application/force-download";
		 };
	 };
	 
	@ob_end_clean();
	header('Content-Type: text/plain' );
	header('Content-Disposition: attachment; filename="yearly_income_'.date('mY').'_'.rand(1000,9999).'.txt"');
	header("Content-Transfer-Encoding: binary");
	header('Accept-Ranges: bytes'); 
	header("Cache-control: private");
	header('Pragma: private');
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
	 //echo '<pre>';
 ?> 
<?php
	$query = "
			SELECT DISTINCT a.karyawan_id FROM karyawan a 
			INNER JOIN pr_yearly_income_karyawan c ON c.karyawan_id=a.karyawan_id
			AND c.pr_yearly_income_id={$pr_yearly_income_id} 		
			WHERE ( a.nik BETWEEN {$_GET['nik_start']} AND {$_GET['nik_end']} )
			ORDER BY a.karyawan_id		
	"; 

	$result = my_query($query );
	while($row = my_fetch_array($result )):
		$karyawan = loaddata_karyawan($row['karyawan_id']);
		$jabatan = my_get_data_by_id('jabatan','jabatan_id',$karyawan['jabatan_id']);
		$golongan_jabatan = my_get_data_by_id('golongan_jabatan','golongan_jabatan_id',$jabatan['golongan_jabatan_id']);
		$pr_yearly_incomes=my_get_data_by_id('pr_yearly_income','pr_yearly_income_id',$pr_yearly_income_id) ;
		$yearly_income_id = isset( $pr_yearly_incomes['yearly_income_id'] ) ? $pr_yearly_incomes['yearly_income_id']:  0;
		$yearlys = my_get_data_by_id('yearly_income','yearly_income_id',$yearly_income_id );

?>
 
<?php echo str_pad('P.T.  K R A K A T A U  M E D I K A',70," ", STR_PAD_BOTH); ?> 
<?php echo str_pad('SLIP '.$yearlys['label'].' '.
date('Y',strtotime($pr_yearly_incomes['tanggal'])),70," ", STR_PAD_BOTH); ?> 
			         			                      
  NIK      : <?php echo sprintf('%07d',$karyawan['nik']);?>                      T.M.B.  : <?php echo date('d-m-Y',strtotime($karyawan['tmb'])); ?>
  
  Dept/CCC : <?php echo $jabatan['nomor_posisi']; ?> / <?php echo str_pad($jabatan['pos_biaya'],4);?>              St.Kary : <?php echo ucfirst(str_replace( "Karyawan ","",$karyawan['status_karyawan'])); ?>                     
  Nama     : <?php echo str_pad( $karyawan['nama_gelar'] ,29);?>St.Kel. : <?php echo $karyawan['ptkp_status'].($karyawan['ptkp_tanggung']>0? $karyawan['ptkp_tanggung']: '')?>
  
  Jabatan  : <?php 
  echo (strlen($jabatan['nama_jabatan'])<51) ? $jabatan['nama_jabatan']: substr($jabatan['nama_jabatan'],0,47).'...';
  ?>
  
  _______________________________________________________________  


<?php 
	$komponens = get_data_list($row['karyawan_id'] ,$pr_yearly_income_id );
	if(is_array($komponens)){
		foreach($komponens as $komponen_id => $rupiah){
		$query = "
			SELECT * FROM pr_yearly_income_komponen 
			WHERE pr_yearly_income_id={$pr_yearly_income_id} 
			AND komponen_id={$komponen_id} 
		";				
		$res_komponen = my_query($query );
		$komponens = my_fetch_array($res_komponen);
		if( $komponens['tipe']=='Header'){
			echo '         '.str_pad( substr($komponens['code'].' '.$komponens['label'],0,30) ,30)."\n";  
		}elseif( $komponens['tipe']=='	Detil'){
			echo '         '.str_pad( substr($komponens['code'].' '.$komponens['label'],0,30) ,30).' : Rp.'.  str_pad( rp_format($rupiah)  ,12," ", STR_PAD_LEFT)."\n"; 
		}else{
			echo '         '.str_pad( substr($komponens['code'].' '.$komponens['label'],0,30) ,30).' : Rp.'.  str_pad( rp_format($rupiah)  ,12," ", STR_PAD_LEFT)."\n"; 
		}
	}}?>	
			
<?php echo chr(12); endwhile;?>